<template>
  <a-modal
    :title="isEdit ? '修改配置信息' : '添加配置信息'"
    :visible="show"
    :confirm-loading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    :maskClosable="false"
    width="30%"
    class="procedure-modal"
  >
    <div class="title">
      <a-form-model
        :label-col="{ span: 6 }"
        :wrapper-col="{ span: 14 }"
        :model="reviseForm"
        :rules="reviseformRules"
        ref="reviseForm"
      >
        <a-form-model-item label="配置信息名称" required prop="ConfigKey">
          <a-input v-model="reviseForm.ConfigKey" />
        </a-form-model-item>
        <a-form-model-item label="配置信息值" required prop="ConfigValue">
          <a-textarea
            v-model="reviseForm.ConfigValue"
            style="max-height: 25rem"
          />
        </a-form-model-item>
        <a-form-model-item label="配置信息描述">
          <a-textarea style="resize: none" v-model="reviseForm.Remark" />
        </a-form-model-item>
      </a-form-model>
    </div>
  </a-modal>
</template>

<script>
import { updConfig } from "@/api/ConfigApi";
export default {
  props: ["show", "isEdit", "reviseForm"],
  data() {
    return {
      confirmLoading: false, //moadl表格弹出loading
      reviseformRules: {
        ConfigKey: [
          {
            required: true,
            message: "请填写配置信息名称",
            trigger: "blur",
            help: "",
          },
        ],
        ConfigValue: [
          {
            required: true,
            message: "请填写配置信息值",
            trigger: "blur",
            help: "",
          },
        ],
      }, //添加工序名称校验
    };
  },
  methods: {
    //关闭弹窗
    handleCancel() {
      this.$refs.reviseForm.clearValidate();
      this.$emit("update:show", false);
    },
    //关闭弹窗后的处理
    breakclose() {
      this.$refs.reviseForm.clearValidate();
      this.$emit("break");
    },
    //确认添加/修改
    handleOk() {
      this.$refs.reviseForm.validate(async (valid) => {
        if (valid) {
          this.confirmLoading = true;
          //true为修改 false为新增
          if (this.isEdit) {
            const res = await updConfig(this.reviseForm);
            res.Data == ""
              ? this.$message.info("修改成功")
              : this.$message.info(res.Data);

            this.handleCancel();
            this.breakclose();
            this.confirmLoading = false;
          } else {
            const res = await updConfig(this.reviseForm);
            res.Data == ""
              ? this.$message.info("添加成功")
              : this.$message.info(res.Data);

            this.handleCancel();
            this.breakclose();
            this.confirmLoading = false;
          }
        }
      });
    },
  },
};
</script>

<style lang="less" scoped></style>
